package com.tarena.backing.controller;

import com.tarena.backing.common.enums.UserTypeEnum;
import com.tarena.backing.converter.UserConverter;
import com.tarena.backing.dao.UserMapper;
import com.tarena.backing.pojo.param.UserParam;
import com.tarena.backing.pojo.po.User;
import com.tarena.backing.pojo.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;
@Api(value= "user",tags= "用户")
@Slf4j
@Validated
@RestController
@RequestMapping("/api/user")
public class UserController {
   @Resource
    private UserMapper userMapper;
   @Resource
    UserConverter userConverter;
   @PostMapping("register")
   @ApiOperation("用户注册")
    public void insertUserInfo() {
        log.info("进入inuf方法");
       User user = new User();
            user.setPassword("22");
            user.setCreateTime(new Date());
            user.setImgUrl("a.jpg");
            user.setUserName("测试1356");
            user.setNickName("nickName");
            user.setIsAdmin(UserTypeEnum.USER.getValue());
            userMapper.insert(user);
    }
    @PostMapping("save")
    @ApiOperation("用户保存")
    public void save(@Valid @RequestBody UserParam userParam){
       User user=new  User();
       BeanUtils.copyProperties(userParam, user);
       user.setCreateTime(new Date());
       userMapper.insert(user);



    }
    @ApiOperation("用户详情")
    @GetMapping("detail")
    public UserVo getUserInfoById(Long id){

       User user=userMapper.selectByPrimarykey(id);

       return userConverter.convertParamToVo(user);
    }


}